
import bpy

import 节点.全局控制.Node.节点和插座基类.bl_节点基类 as 基类
import Core.bl_UI配色 as UI配色

import engine.initLIB.load_dll as engineLib
import ctypes

engineLib.flexCAPI.f_创建体素数据变量节点.restype = ctypes.c_bool



def f_update_变量值改变(self, context):
	data = [list('维度'), tuple(self.m_Value)]
	engineLib.flexCAPI.f_node_传入BL数据(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), ctypes.py_object(data));

	if context :
		self.id_data.f_节点数据更新_更新树([self])


class C_Node_体素变量(基类.C_Node_基类):
	bl_dname = 'bl_node_体素变量'
	bl_label = '体素'
	
	m_Value = bpy.props.IntVectorProperty(update=f_update_变量值改变, min=1, name='维度')
	def init(self, context):
		super(C_Node_体素变量, self).f_init(context)

		self.inputs.new('C_Socket_Vec3', name='空间大小')

		self.outputs.new('C_Socket_uVec3', name='维度')
		self.outputs.new('C_Socket_Vec3', name='单元大小')
		self.outputs.new('C_Socket_UI32', name='数量')
		self.outputs.new('C_Socket_iVec3_Array1D', name='键值')
		self.outputs.new('C_Socket_Vec3_Array1D', name='坐标')

		self.outputs['维度'].f_setData((1,1,1))
		
		self.f_toCPP()
		
		self.use_custom_color = True
		self.color = UI配色.g_内部节点颜色


	def f_toCPP(self):
		是否更新 = engineLib.flexCAPI.f_创建体素数据变量节点(ctypes.c_wchar_p(self.id_data.name), ctypes.c_wchar_p(self.name), self.f_getPyObject());
		if 是否更新 :
			f_update_变量值改变(self, None)
			self.inputs['空间大小'].f_update()

	def draw_buttons(self, context, layout):
		col = layout.row()
		col.prop(self, "m_Value")
		

class C_NODE_MENU_体素变量(bpy.types.Operator):
	bl_idname = 'node.node_voxel'
	bl_label = '体素变量'
	bl_options = {'REGISTER', 'UNDO'}
	def execute(operator, context):
		bpy.ops.node.add_node(type='C_Node_体素变量', use_transform=True)
		return {'FINISHED'}

















classes = (
	C_Node_体素变量,
	C_NODE_MENU_体素变量
)

def register():
	for c in classes:
		bpy.utils.register_class(c)
		

def unregister():
	for c in classes:
		bpy.utils.unregister_class(c)



